<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
		<meta charset="utf-8" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>
<body>
<ul class="forminfo" style="margin-top: 20px;">
    	<li><label>选择实习类型</label><select class="forminfo_select" name="Status" id="Status" onchange="selectChanged();" style="width: 150px;" >
								     	<option value="4">学校分配实习</option>
								     	<option value="3">自训企业</option>
								     	<option value="2">专升本</option>
								     	<option value="1">创业</option>
								</select> 
			</li>
    	<div id="Entrepreneurship">	
    	 <li><label>创业单位</label><input name="EnterpriseName" id="entrepreneurshipEnterpriseName" type="text" class="dfinput" maxlength="20"></li>
    	</div>
    	<div id="Self">	
    	 <li><label>实习单位</label><input name="EnterpriseName" id="selfEnterpriseName" type="text" class="dfinput" maxlength="30"></li>
    	 <li><label>单位地址</label><input name="TheAddress" type="text" class="dfinput" maxlength="40"></li>
    	 <li><label>企业联系人</label><textarea class="long_text long_text2" name="TheContact" maxlength="10"></textarea></li>
    	  <li><label>企业联系人电话</label><textarea class="long_text long_text2" name="TheContactPhone" maxlength="15" onblur="phoneOnblur();"></textarea></li> 
    	  </div>
    	  <div id="schoolAssignment">
    	  <li><label>实习单位</label>省份：<select id="dpselect" name="TheProvince" class="forminfo_select" onchange="TheProvince();">
							<c:forEach items="${provinceList}" var="province">
							<option value="${province.provinceId }" >${province.provinceName }</option>
						</c:forEach>
						</select>
							城市：选择城市：<select id="TheCity" name="TheCity" class="forminfo_select" onchange="TheCity();">
							<c:forEach items="${cityList}" var="city">
							<option value="${city.cityId }"  >${city.cityName }</option>
						</c:forEach>
					</select>
					<div style="margin-left:130px;margin-top:10px;" maxlength="40">
					单位：<select id="EnterpriseId" name="EnterpriseId" class="forminfo_select1"  onchange="enterpriseinfo();">
						<c:forEach items="${enterpriseinfoList}" var="enterpriseinfoList">
							<option value="${enterpriseinfoList.id }" >${enterpriseinfoList.name }</option>
						</c:forEach>
					</select>
					</div>
			</li>
    	  <li><label>实习岗位</label><select class="forminfo_select" name="JobId" id="JobId">
								     	<option value="黎明"> -- 待定 -- </option>
								     	<c:forEach items="${jobInfoList}" var="jobInfo">
							<option value="${jobInfo.id }" >${jobInfo.jobName }</option>
						</c:forEach>
								</select> </li>
    	  <li><label>企业指导老师</label><select class="forminfo_select" name="UserAccount" id="UserAccount">
								     <c:forEach items="${enterpriseUserList}" var="enterpriseUser">
							<option value="${enterpriseUser.userAccount}" >${enterpriseUser.userName }</option>
						</c:forEach>
								</select> </li>
		</div>
    	 <li><label>学校指导老师</label><select class="forminfo_select" name="ZGH" id="ZGH">
								     	  <c:forEach items="${teacherInfoList}" var="teacherInfo">
							<option value="${teacherInfo.ZGH }" >${teacherInfo.XM }</option>
						</c:forEach>
								</select> </li>
    	 	<li><label>开始时间</label><input name="startTime" type="text" id="startTime"  onclick="SelectDate(this,'yyyy-MM-dd')" style=" width: 150px;" class="dfinput" maxlength="20"></li>
    	<li><label>结束时间</label><input name="endTime" type="text" id="endTime" onclick="SelectDate(this,'yyyy-MM-dd')" style=" width: 150px;" class="dfinput" maxlength="20"></li>
    	 
    	 
	<li><label>&nbsp;</label><input name="" type="button" class="btn" onclick="submitForm()" value="确认保存"></li>
    </ul>
     <script src="js/jquery-1.7.2.js"></script>
        <script type="text/javascript" src="js/jquery.tips.js"></script>
     <script type="text/javascript" src="js/adddate.js"></script>
       <script src="layer/layer.js"></script>
    <script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
	var a = new Date();
	var month = a.getMonth()+1;
	if(month<10){
		month = "0" +month;
	}
	var day = a.getDate();
	if(day<10){
		day = "0" + day;
	}
	$("#startTime").val(a.getFullYear()+"/"+month+"/"+day);
	$("#endTime").val(a.getFullYear()+"/"+month+"/"+day);
		$("#Self").hide();
		$("#Entrepreneurship").hide();
		$("#schoolAssignment").show();
	function selectChanged() {
		 var ele=document.getElementById('Status');
 	  	 var index=ele.selectedIndex;
 	 	 var val=ele.options[index].value;
 	 	 if(val==4){
 	 		$("#Self").hide();
 	 		$("#Entrepreneurship").hide();
 			$("#schoolAssignment").show();
 	 	 }else if(val==3||val==2){
 	 		$("#Self").show();
 	 		$("#Entrepreneurship").hide();
 			$("#schoolAssignment").hide();
 	 	 }else {
 	 		$("#Self").hide();
 	 		$("#Entrepreneurship").show();
 			$("#schoolAssignment").hide();
		}
 	 	 
 	 	 }
	function TheProvince() {
		 var ele=document.getElementById('dpselect');
		  	var index=ele.selectedIndex;
		 	 var val=ele.options[index].value;
		 	$.ajax({
			type: "POST",
			url: "jobStudent/province.do",
			data: { ProvinceId : val},
			async: true,
			dataType: "json",
			success: function(data) {
				$("#TheCity").empty();
				for(var i in data.cityList){  
					var $str = "<option value="+data.cityList[i].cityId +">"+data.cityList[i].cityName +"</option>";
					$("#TheCity").append($str);  	 
				}
				$("#EnterpriseId").empty();
				for(var i in data.enterpriseinfoList){  
					var $str1 = "<option value="+data.enterpriseinfoList[i].userAccount +">"+data.enterpriseinfoList[i].name +"</option>";
					$("#EnterpriseId").append($str1);  	 
				}
				$("#UserAccount").empty();
				for(var i in data.enterpriseUserList){  
					var $str2 = "<option value="+data.enterpriseUserList[i].id +">"+data.enterpriseUserList[i].userName +"</option>";
					$("#UserAccount").append($str2);  	 
				}
			}
			})
			}
	function TheCity() {
		 var ele=document.getElementById('TheCity');
		  	var index=ele.selectedIndex;
		 	 var val=ele.options[index].value;
		 	$.ajax({
			type: "POST",
			url: "jobStudent/city.do",
			data: { cityId : val},
			async: true,
			dataType: "json",
			success: function(data) {
				$("#EnterpriseId").empty();
				for(var i in data.enterpriseinfoList){  
					var $str = "<option value="+data.enterpriseinfoList[i].id +">"+data.enterpriseinfoList[i].name +"</option>";
					$("#EnterpriseId").append($str);  	 
				}
				$("#UserAccount").empty();
				for(var i in data.enterpriseUserList){  
					var $str1 = "<option value="+data.enterpriseUserList[i].id +">"+data.enterpriseUserList[i].userName +"</option>";
					$("#UserAccount").append($str1);  	 
				}
			}
		})
	}
	function enterpriseinfo() {
		 var ele=document.getElementById('EnterpriseId');
		  	var index=ele.selectedIndex;
		 	 var val=ele.options[index].value;
		 	$.ajax({
			type: "POST",
			url: "jobStudent/enterpriseinfo.do",
			data: { EnterpriseId : val},
			async: true,
			dataType: "json",
			success: function(data) {
				$("#UserAccount").empty();
				for(var i in data.enterpriseUserList){  
					var $str = "<option value="+data.enterpriseUserList[i].id +">"+data.enterpriseUserList[i].userName +"</option>";
					$("#UserAccount").append($str);  	 
				}
			}
		})
	}
	 function phoneOnblur(){
		 	var inp = document.getElementById("TheContactPhone");
			var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
			var result = reg.test(inp.value);
			if (!result) {
				showTips($("input[name='TheContactPhone']"), '手机号格式不对，请重新输入!！');
				return false;
			}
		}
	var XH = '${XH}'
	function submitForm() {
		var ele=document.getElementById('Status');
	  	 var index=ele.selectedIndex;
	 	 var Status=ele.options[index].value;
	 	 if(Status==3||Status==2){
			if ($("#selfEnterpriseName").val()=="") {
				$("#selfEnterpriseName").tips({
					side : 1,
					msg : '	请填写实习单位',
					bg : '#0099FF',
					time : 3
				});
				return false;
			}
			if ($("input[name='TheAddress']").val() == "") {
				showTips($("input[name='TheAddress']"), '请填写单位地址!');
				return false;
			}
			if ($("input[name='TheContact']").val() == "") {
				showTips($("input[name='TheContact']"), '请填写企业联系人!');
				return false;
			}
			
			if ($("input[name='TheContactPhone']").val() =="") {
				showTips($("input[name='TheContactPhone']"), '请填写企业联系人电话!');
				return false;
			}
			var inp = document.getElementById("TheContactPhone");
			var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
			var result = reg.test(inp.value);
			if (!result) {
				showTips($("input[name='TheContactPhone']"), '手机号格式不对，请重新输入!！');
				return false;
			}
				if($("#startTime").val()==''){
					showTips($("input[name='startTime']"), '请选择开始时间!');
					return false;
				}
				if($("#endTime").val()==''){
					showTips($("input[name='endTime']"), '请选择结束时间!');
					return false;
				}
				var e = $.trim($("#startTime").val());
				var f = $.trim($("#endTime").val());
				if(e>f){
				    	showTips($("input[name='endTime']"), '开始时间要迟于结束时间!');
				    	 return false;
				 }
				 var ele=document.getElementById('ZGH');
				  	var index=ele.selectedIndex;
				 	 var val=ele.options[index].value;
					$.ajax({
						type : "POST",
						url : "jobStudent/selfEnterprise_save.do",
						data : {
							XH : XH,
							Status : Status,
							EnterpriseName : $("#selfEnterpriseName").val(),
							TheAddress : $("input[name='TheAddress']").val(),
							TheContact : $("input[name='TheContact']").val(),
							TheContactPhone : $("input[name='TheContactPhone']").val(),
							SchoolTeacher : val,
							startTime :$("input[name='startTime']").val(),
							endTime : $("input[name='endTime']").val()
							},
						async : true,
						dataType : "json",
						success : function(data) {
							if ("success" == data.result) {
								parent.closeAll();
							} else {
								layer.alert('分配失败!', {
									skin : 'layer-ext-moon'
								});
							}
						}
					})
		} else if (Status==1) {
			if ($("#entrepreneurshipEnterpriseName").val()=="") {
				$("#entrepreneurshipEnterpriseName").tips({
					side : 1,
					msg : '	请填写创业单位',
					bg : '#0099FF',
					time : 3
				});
				return false;
			}
			if($("#startTime").val()==''){
				showTips($("input[name='startTime']"), '请选择开始时间!');
				return false;
			}
			if($("#endTime").val()==''){
				showTips($("input[name='endTime']"), '请选择结束时间!');
				return false;
			}
			var e = $.trim($("#startTime").val());
			var f = $.trim($("#endTime").val());
			 if(e>f){
			    	showTips($("input[name='endTime']"), '开始时间要迟于结束时间!');
			    	 return false;
			    }
			 var ele=document.getElementById('ZGH');
			  	var index=ele.selectedIndex;
			 	 var val=ele.options[index].value;
			    $.ajax({
					type : "POST",
					url : "jobStudent/entrepreneurshipEnterprise_save.do",
					data : {
						XH : XH,
						EnterpriseName : $("#entrepreneurshipEnterpriseName").val(),
						SchoolTeacher : val,
						startTime : $("input[name='startTime']").val(),
						endTime : $("input[name='endTime']").val()},
					async : true,
					dataType : "json",
					success : function(data) {
						if ("success" == data.result) {
							parent.closeAll();
						} else {
							layer.alert('分配失败!', {
								skin : 'layer-ext-moon'
							});
						}
					}
				})
		}else{
			if($("#startTime").val()==''){
				showTips($("input[name='startTime']"), '请选择开始时间!');
				return false;
			}
			if($("#endTime").val()==''){
				showTips($("input[name='endTime']"), '请选择结束时间!');
				return false;
			}
			var e = $.trim($("#startTime").val());
			 var f = $.trim($("#endTime").val());
			    if(e>f){
			    	showTips($("input[name='endTime']"), '开始时间要迟于结束时间!');
			    	 return false;
			    }
			   
						var EnterpriseId = document.getElementById('EnterpriseId');
						var index1 = EnterpriseId.selectedIndex;
						var enterpriseId = EnterpriseId.options[index1].value;
						var JobId = document.getElementById('JobId');
						var index2 = JobId.selectedIndex;
						var jobId = JobId.options[index2].value;
						var UserAccount=document.getElementById('UserAccount');
					  	var i=UserAccount.selectedIndex;
					 	 var userAccount =UserAccount.options[i].value;
						alert(userAccount);
						var ZGH=document.getElementById('ZGH');
					  	var index4=ZGH.selectedIndex;
					 	 var zgh =ZGH.options[index4].value;
					 	 $.ajax({
							type : "POST",
							url : "jobStudent/school_assignment.do",
							data : {
								XH : XH,
								PracticeEnterprise : enterpriseId,
								EnterTeacherId : userAccount,
								JobId : jobId,
								SchoolTeacher : zgh,
								startTime : $("input[name='startTime']").val(),
								endTime : $("input[name='endTime']").val()
							},
							async : true,
							dataType : "json",
							success : function(data) {
								if ("success" == data.result) {
									parent.closeAll();
								} else {
									layer.alert('分配失败!', {
										skin : 'layer-ext-moon'
									});
								}
							}
						})  
					}
					}
					function showTips(obj, tips) {
						obj.tips({
							side : 3,
							msg : tips,
							bg : '#e69138',
							time : 2
						});
					}
				</script>
</body>

</html>
